package com.entity;



import java.util.Date;
import java.util.HashMap;
import java.util.Map;



import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import javax.persistence.MapKey;

import javax.persistence.OneToMany;
import javax.persistence.Table;





@Entity
@Table(name="orders")
public class Orders {
	private int id;
	private Date ordersTime;
	private Date endTime;
	private int desk;//桌子号数
	private int state;//0其他     1进行中    2完成
	private Map<Integer,Cartltem> map=new HashMap<Integer,Cartltem>();
    private int price;
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Column(name="orderstime")
	public Date getOrdersTime() {
		return ordersTime;
	}
	public void setOrdersTime(Date ordersTime) {
		this.ordersTime = ordersTime;
	}
	@Column(name="endtime")
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	@Column(name="state")
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	@OneToMany(mappedBy = "orders", cascade = { CascadeType.ALL })
	@MapKey(name="id")
	public Map<Integer, Cartltem> getMap() {
		return map;
	}
	public void setMap(Map<Integer, Cartltem> map) {
		this.map = map;
	}
	@Column(name="price")
	public int getPrice() {
		
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	@Column(name="desk")
	public int getDesk() {
		return desk;
	}
	public void setDesk(int desk) {
		this.desk = desk;
	}
	/*public void addItem(Product product) {
		
	    if(map.containsKey(product.getId())){
	    Cartltem carItem =map.get(product.getId());
	    	if(carItem.getCount()>=1){
	    		int count=carItem.getCount();	
	    		carItem.setCount(++count);
	    	}
	    }else{
	    	Cartltem item=new Cartltem();
	    	item.setProduct(product);
	    	item.setCount(1);
	    	map.put(product.getId(), item);
	    	
	    }	
	}
public void addOrders(Product product) {
		
	    if(map.containsKey(product.getId())){
	    Cartltem carItem =map.get(product.getId());
	    	if(carItem.getCount()>=1){
	    		int count=carItem.getCount();	
	    		carItem.setCount(++count);
	    	}
	    }else{
	    	Cartltem item=new Cartltem();
	    	item.setProduct(product);
	    	item.setCount(1);
	    	map.put(product.getId(), item);
	    	
	    }	
	}*/
	@Override
	public String toString() {
		return "Orders [id=" + id + ", ordersTime=" + ordersTime + ", endTime=" + endTime + ", desk=" + desk
				+ ", state=" + state + ", map=" + map + ", price=" + price + "]";
	}
	
}
